package com.kylingroup.JavaFX.TreeView;

import java.io.File;
import java.util.HashMap;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class FileTreeItem{
    private Label graphic=null;
    private ImageView graphicIcon=null;
    private Image icon=null;
    private File file=null;
    private HashMap<String,Node> fileInfoNodes=null;

    public FileTreeItem(){}
    
    public Label getGraphic() {
        return graphic;
    }

    public ImageView getGraphicIcon() {
        return graphicIcon;
    }
    
    public Image getIcon(){
        return icon;
    }
    
    public File getFile() {
        return file;
    }

    public void setFile(File file){
        this.file=file;
        graphic=new Label(this.file.getName());
        checkFileType(this.file);
    }
    
    public HashMap<String, Node> getFileInfoNodes(){
        return fileInfoNodes;
    }

    public void setFileInfoNodes(HashMap<String, Node> fileInfoNodes){
        this.fileInfoNodes = fileInfoNodes;
    }
    
    public void checkFileType(File file){
        if(file.isDirectory()){
            icon=FileBrowserController.typeicons.get("folder3");
            graphicIcon=new ImageView(icon);
            graphicIcon.setFitWidth(20);
            graphicIcon.setFitHeight(20);
            graphic.setGraphic(graphicIcon);
        }else{
            String type=this.file.getName();
            type=type.substring(type.lastIndexOf(".")+1,type.length());
            graphicIcon=new ImageView(getTypeIcon(type.toLowerCase()));
            graphicIcon.setFitWidth(20);
            graphicIcon.setFitHeight(30);
            graphic.setGraphic(graphicIcon);
        }
    }
    
    public Image getTypeIcon(String type){
        icon=FileBrowserController.typeicons.get(type);
        if(icon==null){
            icon=FileBrowserController.typeicons.get("default");
        }
        return icon;
    }   
}